home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 7 / BBS in a Box - Macintosh - Volume VII (BBS in a Box) (January 1993).iso / Files / Prog / N-P / NodeCompilerSrc.cpt / compilenodes.c next >
Encoding:
C/C++ Source or Header  |  1989-09-09  |  5.2 KB  |  223 lines  |  [TEXT/KAHL]

  1. /* Copyright (c) 1987 Michael E. Connick */
  2.  
  3. #include <String.h>
  4. #include <stdio.h>
  5.  
  6. extern    int        oneSwitch, zone1, zone2, zone3, zone4, zone5, zone6, zone7;
  7. extern    int        zone8, zone9;
  8. extern    char    areaCode[], localNet[];
  9.  
  10. CompileNodes()
  11. {
  12.     char    filename[256], record[513], testChar, net[6], node[6], zone[6];
  13.     char    nodeType, phoneNumber[50], workNumber[50], entryAC[5];
  14.     char    *ptr1, *ptr2, *ptr3, *ptr4, *scriptTable;
  15.     char    selector[50], change_to[50];
  16.     int        netNumber, nodeNumber, ourNet, i, zoneInt, skipSwitch, subscript;
  17.     FILE    *fp, *ufp;
  18.     
  19.     if((fp = fopen(":Tabby:Dialing Script", "r")) != NULL)
  20.         {
  21.         if((scriptTable = NewPtr(30000)) == NULL)
  22.             {
  23.             message("Unable to allocate memory for Dialing Script Table");
  24.             return;
  25.             }
  26.         *scriptTable = '\0';
  27.         while(fgets(record, 512, fp) != NULL)
  28.             {
  29.             if((ptr1 = strchr(record, '\t')) != NULL)
  30.                 *ptr1++ = '\0';
  31.             if((ptr2 = strchr(ptr1, '\n')) != NULL)
  32.                 *ptr2 = '\0';
  33.             strcat(scriptTable, record);
  34.             strcat(scriptTable, "\t");
  35.             strcat(scriptTable, ptr1);
  36.             strcat(scriptTable, "\n");
  37.             }
  38.         }
  39.     else
  40.         {
  41.         if((scriptTable = NewPtr(10)) == NULL)
  42.             {
  43.             message("Unable to allocate memory for Dialing Script Table");
  44.             return;
  45.             }
  46.         *scriptTable = '\0';
  47.         }
  48.     skipSwitch = FALSE;
  49.     ourNet = atoi(localNet);
  50.     if(message("Warning - Tabby Nodes file must be in the 'Tabby' folder!") == FALSE)
  51.         {
  52.         fclose(fp);
  53.         DisposPtr(scriptTable);
  54.         return;
  55.         }
  56.     while(TRUE)
  57.         {
  58.         if(putfile("Tabby Nodes", filename) == FALSE)
  59.             exit();
  60.         if(strcmp("Tabby Nodes", filename) != 0)
  61.             {
  62.             message("Output file must be called Tabby Nodes.");
  63.             continue;
  64.             }
  65.         break;
  66.         }
  67.     if((ufp = fopen(filename,"wb")) == NULL)
  68.         {
  69.         message("CompileNodes - Unable to create Tabby Nodes.");
  70.         exit();
  71.         }
  72.     netNumber = 0;
  73.     while(getfile("TEXT", filename) != FALSE)
  74.         {
  75.         if((fp = fopen(filename,"r")) == NULL)
  76.             {
  77.             message("CompileNodes - Unable to open nodelist.");
  78.             exit();
  79.             }
  80.         while(fgets(record,512,fp) != NULL)
  81.             {
  82.             testChar = record[0];
  83.             if(testChar == ';' || testChar == '\r' || testChar == '\n')
  84.                 continue;
  85.             ptr1 = strchr(record,',');
  86.             *ptr1 = '\0';
  87.             if(strcmp(record,"Zone") == 0)
  88.                 {
  89.                 skipSwitch = FALSE;
  90.                 ptr3 = ptr1;
  91.                 ptr3++;
  92.                 ptr2 = strchr(ptr3,',');
  93.                 *ptr2 = '\0';
  94.                 strcpy(zone,ptr3);
  95.                 *ptr2 = ',';
  96.                 zoneInt = atoi(zone);
  97.                 if(zoneInt == 1 && zone1 != TRUE)
  98.                     skipSwitch = TRUE;
  99.                 else if(zoneInt == 2 && zone2 != TRUE)
  100.                     skipSwitch = TRUE;
  101.                 else if(zoneInt == 3 && zone3 != TRUE)
  102.                     skipSwitch = TRUE;
  103.                 else if(zoneInt == 4 && zone4 != TRUE)
  104.                     skipSwitch = TRUE;
  105.                 else if(zoneInt == 5 && zone5 != TRUE)
  106.                     skipSwitch = TRUE;
  107.                 else if(zoneInt == 6 && zone6 != TRUE)
  108.                     skipSwitch = TRUE;
  109.                 else if(zoneInt == 7 && zone7 != TRUE)
  110.                     skipSwitch = TRUE;
  111.                 else if(zoneInt == 8 && zone8 != TRUE)
  112.                     skipSwitch = TRUE;
  113.                 else if(zoneInt == 9 && zone9 != TRUE)
  114.                     skipSwitch = TRUE;
  115.                 if(skipSwitch == TRUE)
  116.                     continue;
  117.                 nodeType = 'r';
  118.                 }
  119.             else if(skipSwitch == TRUE)
  120.                 continue;
  121.             else if(strcmp(record,"Region") == 0)
  122.                 {
  123.                 nodeType = 'r';
  124.                 }
  125.             else if(strcmp(record,"Host") == 0)
  126.                 {
  127.                 rotateCursor();
  128.                 nodeType = 'h';
  129.                 }
  130.             else if(strcmp(record,"Hub") == 0)
  131.                 {
  132.                 nodeType = 'b';
  133.                 }
  134.             else if(strcmp(record,"") == 0)
  135.                 {
  136.                 nodeType = ' ';
  137.                 }
  138.             else
  139.                 continue;
  140.             ptr1++;
  141.             ptr2 = strchr(ptr1,',');
  142.             *ptr2 = '\0';
  143.             strcpy(net,ptr1);
  144.             if(nodeType == 'h' || nodeType == 'r')
  145.                 netNumber = atoi(net);
  146.             nodeNumber = atoi(net);
  147.             if(nodeType == 'b' && netNumber != ourNet)
  148.                 continue;
  149.             ptr1 = ptr2+1;
  150.             ptr2 = strchr(ptr1,',');
  151.             ptr1 = ptr2+1;
  152.             ptr2 = strchr(ptr1,',');
  153.             ptr1 = ptr2+1;
  154.             ptr2 = strchr(ptr1,',');
  155.             ptr1 = ptr2+1;
  156.             ptr2 = strchr(ptr1,',');
  157.             *ptr2 = '\0';
  158.             strcpy(workNumber,ptr1);
  159.             ptr1 = workNumber;
  160.  
  161.             phoneNumber[0] = '\0';
  162.             if(workNumber[0] == '1' && workNumber[1] == '-')
  163.                 {
  164.                 if(oneSwitch == TRUE)
  165.                     {
  166.                     phoneNumber[0] = workNumber[0];
  167.                     phoneNumber[1] = '\0';
  168.                     }
  169.                 ptr1 += 2;
  170.                 for(i = 0; *ptr1 != '-'; i++, ptr1++)
  171.                     entryAC[i] = *ptr1;
  172.                 entryAC[i] = '\0';
  173.                 if(strcmp(entryAC, areaCode) == 0)
  174.                     phoneNumber[0] = '\0';
  175.                 else
  176.                     strcat(phoneNumber, entryAC);
  177.                 ptr1++;
  178.                 }
  179.             for(ptr2 = phoneNumber; *ptr2 != '\0'; ptr2++)
  180.                 ;
  181.             for(; *ptr1 != '\0'; ptr1++, ptr2++)
  182.                 if(*ptr1 != '-')
  183.                     *ptr2 = *ptr1;
  184.                 else
  185.                     ptr2--;
  186.             *ptr2 = '\0';
  187.  
  188.             ptr3 = scriptTable;
  189.             while(*ptr3 != '\0')
  190.                 {
  191.                 for(subscript = 0; *ptr3 != '\t'; subscript++)
  192.                     selector[subscript] = *ptr3++;
  193.                 selector[subscript] = '\0';
  194.                 ptr3++;
  195.                 for(subscript = 0; *ptr3 != '\n'; subscript++)
  196.                     change_to[subscript] = *ptr3++;
  197.                 change_to[subscript] = '\0';
  198.                 ptr3++;
  199.                 if((ptr4 = strstr(phoneNumber, selector)) != NULL)
  200.                     {
  201.                     if(ptr4 != phoneNumber)
  202.                         continue;
  203.                     strcpy(workNumber, change_to);
  204.                     ptr4 += strlen(selector);
  205.                     strcat(workNumber, ptr4);
  206.                     strcpy(phoneNumber, workNumber);
  207.                     }
  208.                 }
  209.             fputc(nodeType, ufp);
  210.             fputc((nodeNumber >> 8) & 0x00ff, ufp);
  211.             fputc(nodeNumber & 0x00ff, ufp);
  212.             for(ptr1 = phoneNumber; *ptr1 != '\0'; ptr1++)
  213.                 fputc(*ptr1,ufp);
  214.             fputc('\r',ufp);
  215.             }
  216.         fclose(fp);
  217.         InitCursor();
  218.         }
  219.     fclose(ufp);
  220.     DisposPtr(scriptTable);
  221.     message("Done compiling nodes!");
  222. }
  223.